package com.liziba.es.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @auther LiZiBa
 * @date 2021/2/25 23:26
 * @description:
 **/

@Configuration
public class ElasticsearchConfig {


    /**
     * elasticsearch高亮客户端
     * @param path
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient(@Value("${elasticsearch.node.path:http://127.0.0.1:9200}") String path) {
        String[] split = path.split(":");
        String scheme = split[0];
        String host = split[1].replace("//", "");
        String port = split[2];

        return new RestHighLevelClient(RestClient.builder(new HttpHost(host, Integer.valueOf(port), scheme)));
    }
}
